#include "tcp_server.hpp"
#include "daemon.hpp"
#include <memory>

using namespace std;
using namespace Alpaca;

static void Usage(string proc)
{
    std::cout << "Usage:\n\t" << proc << " port\n"
              << endl;
}

string echo(const string &message)
{
    return message;
}

int main(int argc, char *argv[])
{
    if (argc != 2)
    {
        Usage(argv[0]);
        exit(USAGE_ERR);
    }
    uint16_t port = atoi(argv[1]);
    unique_ptr<TcpServer> tsvr(new TcpServer(echo, port));

    tsvr->InitServer();
    
    daemon();       //将服务器变成守护进程
    tsvr->start();
    return 0;
}